REM (C) G.J. Smit, Nijmegen, Nederland
REM This software is published under the GNU General Public License v3.0
REM www.dbphysics.com
REM Program purpose: db movement analysis

KEY(1) ON: ON KEY(1) GOSUB afrondschoonscherm
KEY(2) ON: ON KEY(2) GOSUB andermode
KEY(3) ON: ON KEY(3) GOSUB nieuwecoordinaten
KEY(4) ON: ON KEY(4) GOSUB windowgrootte
KEY(5) ON: ON KEY(5) GOSUB sterktezwaartekracht
KEY(6) ON: ON KEY(6) GOSUB nieuwaantaldeeltjes
KEY(7) ON: ON KEY(7) GOSUB lijnmetwis
KEY(8) ON: ON KEY(8) GOSUB lijnzonderwis
KEY(9) ON: ON KEY(9) GOSUB willekeuroud
KEY(10) ON: ON KEY(10) GOSUB willekeurnieuw


DIM x(100, 103), y(100, 103), z(100, 103), xfz(100), yfz(100), zfz(100)
DIM x2d(200), y2d(200)

SCREEN 12, 0:  CLS
xyz = 100
mfz = .1
aantal = 3
scherm = 1
begincord = 1
lijn = 0
willoud = 100
willnieuw = 1
wg = 3 * willoud
afrond = 0

WINDOW (-wg, wg)-(wg, -wg)

prog = 1

WHILE prog > 0

CLS

FOR tel = 0 TO aantal - 1
  x(tel, 0) = (RND(1) * 2 * willoud) - willoud: x(tel, 1) = x(tel, 0) + (RND(1) * 2 * willnieuw) - willnieuw
  y(tel, 0) = (RND(1) * 2 * willoud) - willoud: y(tel, 1) = y(tel, 0) + (RND(1) * 2 * willnieuw) - willnieuw
  z(tel, 0) = (RND(1) * 2 * willoud) - willoud: z(tel, 1) = z(tel, 0) + (RND(1) * 2 * willnieuw) - willnieuw
NEXT tel

IF begincord = 1 THEN GOSUB bcord

GOSUB status

prog = 2

WHILE prog > 1

FOR tel1 = 0 TO aantal - 1
  x(tel1, 2) = x(tel1, 1) - x(tel1, 0)
  y(tel1, 2) = y(tel1, 1) - y(tel1, 0)
  z(tel1, 2) = z(tel1, 1) - z(tel1, 0)
  FOR tel2 = tel1 TO aantal - 1
    x(tel1, 3 + tel1) = x(tel2, 1) - x(tel1, 1)
    y(tel1, 3 + tel1) = y(tel2, 1) - y(tel1, 1)
    z(tel1, 3 + tel1) = z(tel2, 1) - z(tel1, 1)
    x(tel2, 3 + tel2) = -x(tel1, 3 + tel1)
    y(tel2, 3 + tel2) = -y(tel1, 3 + tel1)
    z(tel2, 3 + tel2) = -z(tel1, 3 + tel1)
    x(tel1, 3 + aantal + tel1) = ABS(x(tel1, 3 + tel1))
    y(tel1, 3 + aantal + tel1) = ABS(y(tel1, 3 + tel1))
    z(tel1, 3 + aantal + tel1) = ABS(z(tel1, 3 + tel1))
    x(tel2, 3 + aantal + tel2) = ABS(x(tel2, 3 + tel2))
    y(tel2, 3 + aantal + tel2) = ABS(y(tel2, 3 + tel2))
    z(tel2, 3 + aantal + tel2) = ABS(z(tel2, 3 + tel2))
  NEXT tel2
NEXT tel1

FOR tel1 = 0 TO aantal - 1
  xfz(tel1) = 0
  yfz(tel1) = 0
  zfz(tel1) = 0
  FOR tel2 = 0 TO aantal - 1
    IF x(tel1, 3 + aantal + tel2) > 0 THEN xfz(tel1) = xfz(tel1) + x(tel1, 3 + tel2) * mfz / x(tel1, 3 + aantal + tel2)
    IF y(tel1, 3 + aantal + tel2) > 0 THEN yfz(tel1) = yfz(tel1) + y(tel1, 3 + tel2) * mfz / y(tel1, 3 + aantal + tel2)
    IF z(tel1, 3 + aantal + tel2) > 0 THEN zfz(tel1) = zfz(tel1) + z(tel1, 3 + tel2) * mfz / z(tel1, 3 + aantal + tel2)
  NEXT tel2
  x(tel1, 0) = x(tel1, 1)
  IF afrond = 0 THEN x(tel1, 1) = x(tel1, 0) + x(tel1, 2) + xfz(tel1) ELSE x(tel1, 1) = INT(x(tel1, 0) + x(tel1, 2) + xfz(tel1))
  y(tel1, 0) = y(tel1, 1)
  IF afrond = 0 THEN y(tel1, 1) = y(tel1, 0) + y(tel1, 2) + yfz(tel1) ELSE y(tel1, 1) = INT(y(tel1, 0) + y(tel1, 2) + yfz(tel1))
  z(tel1, 0) = z(tel1, 1)
  IF afrond = 0 THEN z(tel1, 1) = z(tel1, 0) + z(tel1, 2) + zfz(tel1) ELSE z(tel1, 1) = INT(z(tel1, 0) + z(tel1, 2) + zfz(tel1))
NEXT tel1

midx = 0
midy = 0
midz = 0

FOR tel = 0 TO aantal - 1
midx = midx + x(tel, 1)
midy = midy + y(tel, 1)
midz = midz + z(tel, 1)
NEXT tel

midx = midx / aantal
midy = midy / aantal
midz = midz / aantal


w2dx = midy - midx * .5
w2dy = midz - midx * .5

IF lijn = 2 THEN GOSUB wislijn:
  
FOR tel = 0 TO aantal - 1
  x2d(tel) = y(tel, 1) - x(tel, 1) * .5
  y2d(tel) = z(tel, 1) - x(tel, 1) * .5
NEXT tel

WINDOW (-wg + w2dx, wg + w2dy)-(wg + w2dx, -wg + w2dy)

IF lijn = 0 THEN GOSUB tekenpunt:  ELSE GOSUB tekenlijn:

WEND
WEND

andermode:
scherm = scherm + 1
IF scherm > 2 THEN scherm = 0
IF scherm = 0 THEN SCREEN 9, 0: WIDTH 80, 43: COLOR 1, 10
IF scherm = 1 THEN SCREEN 12: WIDTH 80, 60
IF scherm = 2 THEN SCREEN 13
GOSUB status
RETURN

afrondschoonscherm:
IF afrond = 0 THEN afrond = 1 ELSE afrond = 0
GOSUB status
RETURN

nieuwecoordinaten:
prog = 1
CLS
RETURN

sterktezwaartekracht:
PRINT "Mate van zwaartekracht is:"; mfz
INPUT "Nieuwe mate:", mfz
GOSUB status
RETURN

nieuwaantaldeeltjes:
PRINT "Aantal deeltjes is:"; aantal
INPUT "Nieuw aantal:", aantal
IF aantal < 1 THEN aantal = 1
IF aantal > 50 THEN aantal = 50
CLS
prog = 1
RETURN

windowgrootte:
PRINT "Windowgrootte is:"; wg
INPUT "Nieuwe grootte:", wg
IF wg < 10 THEN wg = 10
IF wg > 500 THEN wg = 500
GOSUB status:
RETURN

willekeuroud:
PRINT "Randomize oude co rdinaat is:"; willoud
INPUT "Nieuwe randomize factor:"; willoud
IF willoud < 1 THEN willoud = 1
IF willoud > 10000 THEN willoud = 10000
wg = 3 * willoud
CLS
prog = 1
RETURN

willekeurnieuw:
PRINT "Randomize nieuwe co rdinaat is:"; willnieuw
INPUT "Nieuwe randomize factor:"; willnieuw
IF willnieuw < .0000001 THEN willoud = .0000001
IF willnieuw > 1000 THEN willnieuw = 1000
CLS
prog = 1
RETURN


lijnzonderwis:
IF lijn = 1 THEN lijn = 0 ELSE lijn = 1
CLS
IF lijn = 0 THEN GOSUB status:
RETURN

lijnmetwis:
IF lijn = 2 THEN lijn = 0 ELSE lijn = 2
CLS
IF lijn = 0 THEN GOSUB status:
RETURN


bcord:
begincord = 0
x(0, 0) = xyz: x(0, 1) = xyz
y(0, 0) = 0: y(0, 1) = -.9
z(0, 0) = 0: z(0, 1) = .9
x(1, 0) = 0: x(1, 1) = .9
y(1, 0) = xyz: y(1, 1) = xyz
z(1, 0) = 0: z(1, 1) = -.9
x(2, 0) = 0: x(2, 1) = -.9
y(2, 0) = 0: y(2, 1) = .9
z(2, 0) = xyz: z(2, 1) = xyz

RETURN

tekenpunt:

FOR tel = 0 TO aantal - 1
  PSET (x2d(tel), y2d(tel)), 7 + tel
NEXT tel
RETURN

tekenlijn:
FOR tel1 = 0 TO aantal - 1
  FOR tel2 = tel1 TO aantal - 1
  LINE (x2d(tel1), y2d(tel1))-(x2d(tel2), y2d(tel2)), 2 + tel1 + tel2
  NEXT tel2
NEXT tel1
RETURN

wislijn:
CLS
RETURN

status:
CLS
IF scherm = 0 THEN PRINT "EGA (16k)"
IF scherm = 1 THEN PRINT "VGA (16k)"
IF scherm < 2 THEN PRINT "Window-grootte  :"; wg
IF scherm < 2 THEN PRINT "Sterkte Fzwaarte:"; mfz
IF scherm < 2 THEN PRINT "Aantal 1db's    :"; aantal
IF scherm < 2 THEN PRINT "r_oud           :"; willoud
IF scherm < 2 THEN PRINT "r_nieuw         :"; willnieuw
IF scherm < 2 THEN PRINT "Afronding c_oud :"; afrond
RETURN

